import entity.Student;

import java.util.ArrayList;
import java.util.Comparator;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
//        main.test1();
        main.test2();
    }


    public void test1() {
        System.out.println("Hello world!");
        Student zhangsan = new Student("zhangsan", 12);
        String name = zhangsan.name();
        int age = zhangsan.age();
        System.out.println(name + age);
    }


    public void test2() {
        //创建一个ArrayList
        ArrayList<Student> list = new ArrayList<>();
        //向list添加五个Student
        list.add(new Student("zhangsan", 12));
        list.add(new Student("lisi", 13));
        list.add(new Student("wangwu", 14));
        list.add(new Student("zhaoliu", 15));
        list.add(new Student("qianqi", 16));
        //将list进行排序,以Student的年龄进行降序排序
        list.sort((s1, s2) -> s2.age() - s1.age());
        //遍历输出list
        for (Student student : list) {
            System.out.println(student);
        }

        System.out.println("============================");
        //将list升序排序
        list.sort(Comparator.comparingInt(Student::age));
        list.forEach(System.out::println);


    }

}